package com.hecai.scanning;

import com.hecai.scanning.config.ConfigProperties;
import com.hecai.scanning.util.FileDirUtil;
import org.apache.commons.io.FileUtils;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.context.annotation.Bean;

import java.lang.reflect.Method;
import java.util.Properties;

@SpringBootApplication
public class GreenScannerApplication
{
    @Bean
    public ConfigProperties initConfigProperties() throws Exception
    {
        ConfigProperties properties = new ConfigProperties();
        String configPath = FileDirUtil.getResourceFile("config/config.properties");
        Properties proper = new Properties();
        proper.load(FileUtils.openInputStream(FileUtils.getFile(configPath)));
        Method[] methods = properties.getClass().getDeclaredMethods();
        for (Method method : methods)
        {
            String methodName = method.getName();
            if (methodName.startsWith("set"))
            {// 查找set方法
                String propName = methodName.substring(3, 4).toLowerCase() + methodName.substring(4);
                String value = proper.getProperty("config." + propName);
                method.invoke(properties, value);
            }
        }
        return properties;
    }

    public static void main(String[] args)
    {
        SpringApplication.run(GreenScannerApplication.class, args);
    }

}
